{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[2.87070855]\n",
      "41.45069393718042\n",
      "[73.02848795]\n"
     ]
    }
   ],
   "source": [
    "from sklearn.linear_model import LinearRegression\n",
    "\n",
    "# 自变量，每周学习时长\n",
    "X = [[5], [8], [10], [12], [15], [3], [7], [9], [14], [6]]\n",
    "# 因变量，数学考试成绩\n",
    "y = [55, 65, 70, 75, 85, 50, 60, 72, 80, 58]\n",
    "# 实例化线性回归模型\n",
    "model = LinearRegression()\n",
    "# 模型训练\n",
    "model.fit(X, y)\n",
    "# 系数，每周每学习1小时，成绩会增加多少分\n",
    "print(model.coef_)\n",
    "# 截距\n",
    "print(model.intercept_)\n",
    "# 预测,每周学习11小时，成绩可能是多少分\n",
    "print(model.predict([[11]]))"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
